// Package internal
// Created by GoLand
// @User: lenora
// @Date: 2023/11/27
// @Time: 14:55

package main

import (
	"github.com/prometheus/client_golang/prometheus/promhttp"
	"github.com/spf13/viper"
	"log"
	"net/http"
)

func main() {
	//db := initDb()
	//redisClient := initRedis()
	initViper()
	initPrometheus()

	//otelCancel := ioc.InitOtel()
	//defer func() {
	//	ctx, cancel := context.WithTimeout(context.Background(), time.Second)
	//	defer cancel()
	//	otelCancel(ctx)
	//}()
	//server := initWebServer(redisClient)
	app := InitApp()

	for _, consumer := range app.consumer {
		if err := consumer.Start(); err != nil {
			panic(err)
		}
	}

	err := app.server.Serve()
	if err != nil {
		panic(err)
	}

}

func initViper() {
	//读取的配置文件类型
	viper.SetConfigType("yaml")
	//读取的配置文件名称
	viper.SetConfigName("dev")
	//当前工作目录下的config目录
	viper.AddConfigPath("config")
	//最终配置文件为:./config/dev.yaml
	//读取配置
	err := viper.ReadInConfig()
	if err != nil {
		panic(err)
	}
	v := viper.Get("api.auth")
	log.Println(v)
}

func initPrometheus() {
	go func() {
		//专门提供给prometheus的端口
		http.Handle("/metrics", promhttp.Handler())
		_ = http.ListenAndServe(":8084", nil)
	}()
}
